package com.example.myspringframework.beans.factory.support;

import com.example.myspringframework.beans.BeansException;
import com.example.myspringframework.beans.factory.config.BeanDefinitionRegistry;
import com.example.myspringframework.core.io.DefaultResourceLoader;
import com.example.myspringframework.core.io.ResourceLoader;

/**
 * 加载BeanDefinition的抽象类
 */
public abstract class AbstractBeanDefinitionReader implements BeanDefinitionReader {
    // BeanDefinition注册器
    private final BeanDefinitionRegistry beanDefinitionRegistry;
    // 资源加载器
    private final ResourceLoader resourceLoader;

    public AbstractBeanDefinitionReader(BeanDefinitionRegistry beanDefinitionRegistry) {
        this(beanDefinitionRegistry, new DefaultResourceLoader());
    }

    public AbstractBeanDefinitionReader(BeanDefinitionRegistry beanDefinitionRegistry, ResourceLoader resourceLoader) {
        this.beanDefinitionRegistry = beanDefinitionRegistry;
        this.resourceLoader = resourceLoader;
    }

    @Override
    public BeanDefinitionRegistry getBeanDefinitionRegistry() {
        return this.beanDefinitionRegistry;
    }

    @Override
    public ResourceLoader getResourceLoader() {
        return this.resourceLoader;
    }

    @Override
    public void loadBeanDefinitions(String[] locations) throws BeansException {
        for(String location:locations){
            this.loadBeanDefinitions(location);
        }
    }

}
